package crm.view.Employee;

import crm.Utils.RoundBorder;
import crm.dao.impl.EmployeeSqlSeverImpl;
import crm.dao.impl.PlanSqlSeverImpl;
import crm.entity.Customer;
import crm.entity.Employee;
import crm.entity.Plan;
import crm.view.Custom.LoginBasicCustom;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

/**
 * 查看职员计划
 */
public class EmployeePlan implements ActionListener {
    JFrame frame = null;
    JLabel name = null;
    JLabel PlanId = null;
    JLabel contactId = null;
    JLabel consumerName = null;
    JLabel planProfit = null;
    JLabel planTime = null;
    JLabel isFinished = null;
    JLabel implementation = null;

    JTextField nameField = null;
    JTextField PlanIdField = null;
    JTextField contactIdField = null;
    JTextField consumerNameField = null;
    JTextField planProfitField = null;
    JTextField planTimeField = null;
    JTextField isFinishedField = null;
    JTextField implementationField = null;

    JButton btn = null;
    JButton btn2 = null;


    public static void main(String[] args) {
        new EmployeePlan();
    }

    public EmployeePlan() {
        init();
        frame.setBounds(680, 200, 600, 550);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setLayout(null);
        frame.setVisible(true);
    }

    public void init() {
        frame = new JFrame("查看职员计划");
        name = new JLabel("请输入您的姓名:");
        PlanId = new JLabel("计划编号:");
        contactId = new JLabel("联系人编号:");
        consumerName = new JLabel("客户名称:");
        planProfit = new JLabel("计划利润:");
        planTime = new JLabel("计划时间");
        isFinished = new JLabel("是否按计划完成:");
        implementation = new JLabel("实施情况:");
        btn = new JButton("查询");
        btn2 = new JButton("清空");

        nameField = new JTextField();
        PlanIdField = new JTextField();
        PlanIdField.setEditable(false);
        contactIdField = new JTextField();
        contactIdField.setEditable(false);
        consumerNameField = new JTextField();
        consumerNameField.setEditable(false);
        planProfitField = new JTextField();
        planProfitField.setEditable(false);
        planTimeField = new JTextField();
        planTimeField.setEditable(false);
        isFinishedField = new JTextField();
        isFinishedField.setEditable(false);
        implementationField = new JTextField();
        implementationField.setEditable(false);
        Font font = new Font("宋体", 2, 20);
        name.setFont(font);
        nameField.setFont(font);
        PlanId.setFont(font);
        PlanIdField.setFont(font);
        contactId.setFont(font);
        contactIdField.setFont(font);
        consumerName.setFont(font);
        consumerNameField.setFont(font);
        planProfit.setFont(font);
        planProfitField.setFont(font);
        planTime.setFont(font);
        PlanIdField.setFont(font);
        isFinished.setFont(font);
        isFinishedField.setFont(font);
        implementation.setFont(font);
        implementationField.setFont(font);
        btn.setFont(font);
        btn2.setFont(font);

        ImageIcon icon1 = new ImageIcon("src/img/查询2.png");
        btn.setIcon(icon1);
        btn.setOpaque(false);
        btn.setBorder(new RoundBorder());
        btn.setBorder(new RoundBorder(Color.PINK));
        ImageIcon icon2 = new ImageIcon("src/img/清空.png");
        btn2.setIcon(icon2);
        btn2.setOpaque(false);
        btn2.setBorder(new RoundBorder());
        btn2.setBorder(new RoundBorder(Color.PINK));
        frame.add(btn);
        frame.add(btn2);
        frame.add(name);
        frame.add(nameField);
        frame.add(PlanId);
        frame.add(PlanIdField);
        frame.add(contactId);
        frame.add(contactIdField);
        frame.add(consumerName);
        frame.add(consumerNameField);
        frame.add(planProfit);
        frame.add(planProfitField);
        frame.add(planTime);
        frame.add(planTimeField);
        frame.add(isFinished);
        frame.add(isFinishedField);
        frame.add(implementation);
        frame.add(implementationField);

        name.setBounds(40, 5, 160, 60);
        nameField.setBounds(210, 5, 300, 40);
        btn.setBounds(200, 50, 120, 40);
        btn2.setBounds(350, 50, 120, 40);
        PlanId.setBounds(40, 90, 100, 60);
        PlanIdField.setBounds(210, 100, 300, 40);
        contactId.setBounds(40, 140, 160, 60);
        contactIdField.setBounds(210, 150, 300, 40);
        consumerName.setBounds(40, 190, 100, 60);
        consumerNameField.setBounds(210, 200, 300, 40);
        planProfit.setBounds(40, 240, 100, 60);
        planProfitField.setBounds(210, 250, 300, 40);
        planTime.setBounds(40, 290, 100, 60);
        planTimeField.setBounds(210, 300, 300, 40);
        isFinished.setBounds(40, 340, 160, 60);
        isFinishedField.setBounds(210, 350, 300, 40);
        implementation.setBounds(40, 390, 100, 60);
        implementationField.setBounds(210, 400, 300, 40);
        btn.addActionListener(this);
        btn2.addActionListener(this);
    }


    @Override
    public void actionPerformed(ActionEvent e) {
        Plan plan = new Plan();
        PlanSqlSeverImpl dao = new PlanSqlSeverImpl();
        String name = nameField.getText();


        if ("查询".equals(e.getActionCommand())) {
            if ("".equals(name)){
                JOptionPane.showMessageDialog(null, "请输入用户姓名进行查询！");
            }else{
                List<Plan> getname = dao.getByName(name);
                for (Plan employee1 : getname) {
                    nameField.setText(String.valueOf(employee1.getEmployee_name()));
                    PlanIdField.setText(String.valueOf(employee1.getPlan_id()));
                    contactIdField.setText(String.valueOf(employee1.getContact_id()));
                    consumerNameField.setText(String.valueOf(employee1.getCustomer_name()));
                    planProfitField.setText(String.valueOf(employee1.getPlan_profit()));
                    planTimeField.setText(String.valueOf(employee1.getPlan_time()));
                    isFinishedField.setText(String.valueOf(employee1.isFinished()));
                    implementationField.setText(String.valueOf(employee1.getImplementation()));


                }


            }
        } else if ("清空".equals(e.getActionCommand())) {
            nameField.setText("");
            PlanIdField.setText("");
            contactIdField.setText("");
            consumerNameField.setText("");
            planProfitField.setText("");
            planTimeField.setText("");
            isFinishedField.setText("");
            implementationField.setText("");
        }


//        if ("查询".equals(e.getActionCommand())) {
//            if ("".equals(name){
//                JOptionPane.showMessageDialog(null, "请输入用户姓名进行查询！");
//            }else{
//                List<Employee> getname = dao.getByName(name);
//                for (Employee employee1 : getname) {
//
//                }
//
//            }
//        } else if ("清空".equals(e.getActionCommand())) {
//            nameField.setText("");
//
//        }


    }
}
